package com.itheima.mall.controller.smsController;


import cn.hutool.db.PageResult;
import com.itheima.mall.commons.R;
import com.itheima.mall.service.smsService.SmsFlashPromotionProductRelationService;
import com.itheima.pojo.sms.SmsFlashPromotionProductRelation;
import com.itheima.vo.PmsProVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController {

    @Autowired
    private SmsFlashPromotionProductRelationService smsFlashPromotionProductRelationService;
    /**
     * 批量选择商品添加关联
     */
    @PostMapping("create")
    public R addFlashProductRelation(@RequestBody SmsFlashPromotionProductRelation smsFlashPromotionProductRelation){
        return smsFlashPromotionProductRelationService.addFlashProductRelation(smsFlashPromotionProductRelation);
    }
    /**
     * 删除商品关联
     */
    @PostMapping("delete/{id}")
    public R deleteFlashProductRelation(@PathVariable Integer id){
        return smsFlashPromotionProductRelationService.deleteFlashProductRelation(id);
    }
    /**
     * 分页查询不同场次关联及商品信息
     * flashPromotionId @param
     * flashPromotionSessionId  @param
     * 当前页码 @param pageNum
     * 当前页条目数 @param pageSize
     * @return
     */
  /*  @GetMapping("list")
    public R selectByPage(Integer flashPromotionId,
                          Integer flashPromotionSessionId,
                          @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        PageResult<PmsProVo> res = smsFlashPromotionProductRelationService.selectByPage(flashPromotionId,flashPromotionSessionId,pageNum,pageSize);
        return R.ok(res);
    }*/

    /**
     * 修改关联信息
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Long id,@RequestBody SmsFlashPromotionProductRelation smsFlashPromotionProductRelation){
        return   smsFlashPromotionProductRelationService.update(id,smsFlashPromotionProductRelation);
    }

    /**
     * 获取管理商品促销信息
     * id
     */
    @GetMapping("{id}")
    public R selectProductionMessage(@PathVariable Long id){
        return smsFlashPromotionProductRelationService.selectProductionMessage(id);
    }

}
